define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            //自定义参数 传入 后端 buildparams() 接收
            $('.nav-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var value = $(this).data("value");
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    params.paytype = value;
                    return params;
                };
                //table.bootstrapTable('refresh', {});
                return false;

            });

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'projectlist/index',
                    add_url: 'projectlist/add',
                    edit_url: 'projectlist/edit',
                    del_url: 'projectlist/del',
                    multi_url: 'projectlist/multi',
                    dragsort_url: '',
                    import_url: 'projectlist/import',
                    check_url: 'projectlist/check',
                    table: 'category',
                },


            });

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                searchFormVisible:false,
                search:false,
                columns: [
                    [
                         {checkbox: true},
                         {field: 'id', title: __('Id'),operate: false},
                         {field:'title', title: __('projectname'),operate:'LIKE'},
                         {field: 'img', title: __('Image'), operate: false, formatter: Table.api.formatter.image},//height:'50px'
                        {field: 'status', title: '状态',searchList:{"0":'正常',"1":'超前',"2":'滞后',"3":'完成'},formatter:Table.api.formatter.normal},
                        {field:'psdate', title:'本年度开始时间',operate:false},
                        {field:'pedate', title:'本年度结束时间',operate: false,},
                        {field:'itempecent', title:'本年度任务目标',operate: false,},
                        {field:'userpercent', title:'本年度完成工作量自评',operate: false,},
                        {field:'percent', title:'本年度单次任务目标',operate: false,},
                        {field:'hbdate', title:'汇报日期', operate:false},
                        {field:'hbcdate', title:'汇报日期(双月)', operate:'BETWEEN', addclass:'datetimepicker', formatter: Table.api.formatter.dateday, data: 'data-date-format="YYYY-MM-DD"' },
                        {field: 'createtime', title: __('createtime'),width:'150px', operate:'RANGE', formatter: Table.api.formatter.datetime, data: 'data-date-format="MM-DD"',operate: false},
                         {field: 'operate', title: __('Operate'), width:'100px',table: table,
                             events: Table.api.events.operate, formatter: Table.api.formatter.operate},

                    ]
                ]
            };


            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["80%","90%"]);
            })

            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);



            //必须默认触发shown.bs.tab事件
            // $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");

        },
        add: function () {
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                //建设单位
                var bid = $("#p_bid").attr("ids");
                $("#p_bid ")
                $("#p_bid option[data-type='"+ bid +"']").prop("selected", true);
                //项目等级
                var lid = $("#p_lid").attr("ids");
                $("#p_lid ")
                $("#p_lid option[data-type='"+ lid +"']").prop("selected", true);
                //当前阶段
                var sid = $("#p_sid").attr("ids");
                $("#p_sid ")
                $("#p_sid option[data-type='"+ sid +"']").prop("selected", true);
                //所属板块
                var cid = $("#p_cid").attr("ids");
                $("#p_cid ")
                $("#p_cid option[data-type='"+ cid +"']").prop("selected", true);


/*                $(document).on("change", "#c-type", function () {

                    $("#c-pid option[data-type='all']").prop("selected", true);
                    $("#c-pid option").removeClass("hide");
                    $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
                    $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
                });*/
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
